﻿using AuthoritExtensibility;

namespace ImporterForm
{
    /// <summary>
    /// Implements the code that associates the plug-in with Author-it.
    /// </summary>
    internal class PluginManager : IPlugin
    {
        #region Fields (2)

        private ToolbarAddArgs mainFormArgs;
        private AitApplicationProxy myProxy;

        #endregion Fields

        #region Constructors (1)

        /// <summary>
        /// Initializes a new instance of the <see cref="PluginManager"/> class.
        /// </summary>
        /// <param name="proxy">Application proxy that Author-it passes to the plug-in</param>
        public PluginManager(AitApplicationProxy proxy)
        {
            myProxy = proxy;
            mainFormArgs = new ToolbarAddArgs();
            mainFormArgs.IconImage = Properties.Resources.Ico;
            mainFormArgs.PluginName = "XmlImport";  //TODO: Move "XmlImport" value to a resource
            mainFormArgs.TargetForm = TargetForm.MainForm;
            mainFormArgs.TargetGroupName = "Web";  //TODO: Move "Web" value to a resource
            mainFormArgs.TargetButtonName = "XML Import";  //TODO: Move "XML Import" value to a resource
            mainFormArgs.Tooltip = "XML Importer";  //TODO: Move "XML Importer" value to a resource
            mainFormArgs.OnClick = clickHandler;
            proxy.AddPluginToToolbar(mainFormArgs);
        }

        #endregion Constructors

        #region Methods (1)

        // Private Methods (1) 

        /// <summary>
        /// Handles the click event for the toolbar button.
        /// </summary>
        /// <param name="sender">Object that initiated the event</param>
        /// <param name="e">Arguments for the event</param>
        private void clickHandler(object sender, AuthoritEventArgs e)
        {
            ImporterForm form = new ImporterForm(e, myProxy);
            form.ShowDialog();
        }

        #endregion Methods
    }
}